package client

import (
	"gitee.com/zawei/yggdrasil/pkg"
	"gitee.com/zawei/yggdrasil/pkg/log"
	"gitee.com/zawei/yggdrasil/pkg/metrics"
)

const (
	MetricsHandleTotal = "client_handle_total"
	MetricsHandleSec   = "client_handle_seconds"
)

func registerMetric() {
	err := metrics.CreateCounter(metrics.CounterOpts{
		Namespace: pkg.FrameworkName(),
		Subsystem: pkg.AppName(),
		Name:      MetricsHandleTotal,
		Labels:    []string{"type", "name", "method", "peer", "code"},
	})
	if err != nil {
		log.Fatal(err)
	}

	err = metrics.CreateHistogram(metrics.HistogramOpts{
		Namespace: pkg.FrameworkName(),
		Subsystem: pkg.AppName(),
		Name:      MetricsHandleSec,
		Labels:    []string{"type", "name", "method", "peer"},
	})
	if err != nil {
		log.Fatal(err)
	}
}

func init() {
	registerMetric()
}
